package Person;

import java.util.Scanner;

public class xunzhaomima {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String x = sc.next();
        int n=sc.nextInt();
        int hangshu=-1;
        int i=-1;
        int cou=0;
        String str = sc.next();
    while(sc.hasNext()){
        if(str=="end"){
            break;
        }
        hangshu++;
        i=str.indexOf(x);
        if(i!=-1){
            System.out.println(hangshu+" "+str);
            cou++;
            if(cou==n){
                break;
            }
        }
        str=sc.nextLine();
    }
        System.out.println(cou);

    }
}
